package com.erlang.spring.proxy;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Description：cglib动态代理
 */
public class CglibProxy implements MethodInterceptor {

    private Object targClass;

    private String joinPoint = "saveAccount";

    public CglibProxy(Object targClass) {
        this.targClass = targClass;
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        Object object = null;
        if (joinPoint.equals(method.getName())){
            System.out.println("Cglib增强："+method.getName());
        }
        object = method.invoke(targClass, objects);
        return object;
    }
}